package com.tanhua.server.controller;


import com.alibaba.dubbo.common.utils.CollectionUtils;
import com.tanhua.dubbo.server.pojo.Report;
import com.tanhua.server.pojo.Answers;
import com.tanhua.server.service.SoulService;
import com.tanhua.server.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("testSoul")
public class SoulController {

    @Autowired
    private SoulService soulService;

    /**
     * 查询试卷
     * @return
     */
    @GetMapping
    public ResponseEntity<List<ResultVo>> paperList(){
        List<ResultVo> testVoList = this.soulService.paperList();
        if(!CollectionUtils.isEmpty(testVoList)){
            return ResponseEntity.ok(testVoList);
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }


    /**
     * 保存报告
     * @param map
     * @return
     */
    @PostMapping
    public ResponseEntity<String> saveReport(@RequestBody Map<String, List<Answers>> map){

        List<Answers> answers = map.get("answers");
        String result = this.soulService.saveReport(answers);
        if(null != result){
            return ResponseEntity.ok(result);
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }


    @GetMapping("report/{id}")
    public ResponseEntity<Report> queryReport(@PathVariable("id") String id) {
        Report report = this.soulService.queryReport(id);
        if (report!=null){
            return ResponseEntity.ok(report);
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

//    public ResponseEntity<Report> queryReport(@PathVariable("id") String id){
//
//        Report report = this.soulService.queryReport(id);
//        if(report != null){
//            return ResponseEntity.ok(report);
//        }
//
//        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
//
//    }

}
